﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using TimKen.DataEntity;
using TimKen.BussLogic;
using System.Data;
using TimKen.DataAccess;


namespace TimKen.Web.Admin.Brand
{
    public partial class Brand_List : TimKen.App.AdminPage
    {
        private PBrandManager ttm = new PBrandManager();

        public override string ActionCode
        {
            get
            {
                return "9";
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }

        protected void grdBrand_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "EditEvent")
            {
                int brandID = Convert.ToInt32(e.CommandArgument);
                if (!string.IsNullOrEmpty(this.hidValue.Value))
                {
                    Response.Redirect("Brand_Add.aspx?BrandID=" + brandID);
                }
            }
            if (e.CommandName == "DeleteEvent")
            {
                int brandID = Convert.ToInt32(e.CommandArgument);
                if (!string.IsNullOrEmpty(this.hidValue.Value))
                {
                    ttm.Delete(brandID);
                    BindData();
                }
            }
            if (e.CommandName == "ord_up")
            {
                string brandName = e.CommandArgument.ToString();
                if (!string.IsNullOrEmpty(this.hidValue.Value))
                {
                    string thisNum = this.hidValue.Value.Split(':')[0];
                    string upNum = this.hidValue.Value.Split(':')[1];
                    string cmdText = String.Format("UPDATE PBrand SET BrandID = {0} WHERE  BrandID ={1}", thisNum, upNum);
                    string cmd = String.Format("UPDATE PBrand SET BrandID = {0} WHERE  Name ='{1}'", upNum, brandName);

                    DbHelperSQL.ExecuteSql(cmdText);
                    DbHelperSQL.ExecuteSql(cmd);
                    BindData();
                }
            }
            if (e.CommandName == "ord_down")
            {

            }
        }


        private void BindData()
        {
            DataSet ds = ttm.GetAllList();
            this.grdBrand.DataSource = ds;
            this.grdBrand.DataBind();
        }
    }
}
